<?php
	if (!session_start()) session_start();
	require_once("../../../librarys/funcs/Connection.php");
	require_once("../../../librarys/funcs/Utils.php");

	$conn = new Connection();
	$util = new Utils();

	$table        = "product";
	$now          = getdate();
	$current_time = $util->getCurrentDayString();
	$catalog      = $_POST['catalog'];
	$catalog1     = $_POST['catalog1'];
	$title        = $util->safeString($_POST['title']);
	$desc         = $util->safeString(($_POST['desc']));
	$price        = $_POST['price'];
	$price2       = $_POST['price2'];
	$url_image    = trim($_POST['url_image']);
	$content      = $util->safeStringDecode($_POST['content']);

	// echo $content;
	$attributes = array(
		'title'       => $util->add_single_quote($title),
		'description' => $util->add_single_quote($desc),
		'content'     => $util->add_single_quote($content),
		'catalog_id'  => $util->add_single_quote($catalog),
		'catalog1_id' => $util->add_single_quote($catalog1),
		'created'     => $util->add_single_quote($current_time),
		'price'       => $util->add_single_quote($price),
		'price2'      => $util->add_single_quote($price2),
		'url_image'   => $util->add_single_quote($url_image),
		'count'       => $util->add_single_quote(0),
		'status'      => $util->add_single_quote(1),
	);
	$result     = $conn->insert($table, $attributes);
	if ($result > 0)
		echo "Thêm thành thành công! <a href='index.php?p=" . $table . "&t=edit&id=$result'>Click here</a> để cập nhật thông tin vừa mới nhập";
	else {
		echo "Lỗi ở server, xin thử thử lại lần nữa!";
	}

?>